package top.igotcha.servicebase.handler;

import top.igotcha.commonutils.exception.GuliException;
import top.igotcha.commonutils.utils.R;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author Gotcha
 * @date 2021/8/1
 * @describe 统一异常处理类
 */

@ControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public R error(Exception e){
        e.printStackTrace();
        return R.ERROR().message("未知异常");
    }


    @ExceptionHandler(GuliException.class)
    @ResponseBody
    public R error(GuliException e){
        e.printStackTrace();
        return R.ERROR().message(e.getMsg()).code(e.getCode());
    }
}
